package com.uenpay.im.ui.old.activity.wallet;

import android.util.Log;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class ChargeInvokItem extends HttpInvokeItem {

    public class ChargeInvokItemResult extends HttpInvokeResult {
        public String app_id;
        public String method;
        public String charset;
        public String sign_type;
        public String sign;
        public String timestamp;
        public String version;
        public String notify_url;
        public String biz_content;
    }

    public ChargeInvokItemResult getOutput() {
        return (ChargeInvokItemResult) GetResultObject();
    }

    public ChargeInvokItem(String amount) {
        String url = APIConfiguration.getBaseUrl() + "Purse/Purse/charge?amount="
                + amount + "&" + APIConfiguration.getCustIdAndToken();
        Log.e("地址：",url);
        SetUrl(url);
    }

    @Override
    protected Object DeserializeResult(String responseBody) {
        Log.e("结果：",responseBody);
        ChargeInvokItemResult result = new ChargeInvokItemResult();
        try {
            JSONObject json = new JSONObject(responseBody);
            result.status = json.optInt("status");
            result.msg = json.optString("msg");
            JSONObject dataJson = json.optJSONObject("data");
            if (dataJson != null && dataJson.has("body")) {
                String bodyStr = dataJson.optString("body");
                JSONObject bodyJson = new JSONObject(bodyStr);
                if (bodyJson != null) {
                    result.sign = bodyJson.optString("sign");
                    result.notify_url = bodyJson.optString("notify_url");
                    result.app_id = bodyJson.optString("app_id");
                    result.charset = bodyJson.optString("charset");
                    result.sign_type = bodyJson.optString("sign_type");
                    result.timestamp = bodyJson.optString("timestamp");
                    result.biz_content = bodyJson.optString("biz_content");
                    result.method = bodyJson.optString("method");
                    result.version = bodyJson.optString("version");
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
            return result;
        }

        return result;
    }

}
